Refactor AppCode to support custom SCREAMING_SNAKE_CASE codes#136
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| pub struct AppCode { | ||
| repr: CodeRepr | ||
| } | ||
|
|
||
| /// Database-related failure (query, connection, migration, etc.). | ||
| /// | ||
| /// Typically mapped to HTTP **500 Internal Server Error**. | ||
| Database, | ||
| #[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
| enum CodeRepr { | ||
| Static(&'static str), | ||
| Owned(Box<str>) |
There was a problem hiding this comment.
[P1] Normalize AppCode equality across static and dynamic instances
Equality for AppCode currently derives from the CodeRepr enum, so codes backed by a static literal (CodeRepr::Static) never compare equal to dynamically constructed codes (CodeRepr::Owned) even when their textual representation matches. As a result, code lookups such as mapping_for_code(&AppCode::try_new("NOT_FOUND").unwrap()) fall through to the default mapping instead of returning the NOT_FOUND mapping, and any HashMap keyed by AppCode will treat equivalent codes as distinct keys. Equality (and hashing) should be based on as_str() rather than the storage variant so that custom codes created via try_new behave identically to built‑in constants.
Useful? React with 👍 / 👎.
Summary
AppCodeenum with a validated string-backed newtype and exposeAppCode::new/AppCode::try_newTesting
https://chatgpt.com/codex/tasks/task_e_68d6843a9710832bbc90c2d9af8492ab